<?php

namespace App\Wechat;

/***
 * 菜单栏扫码等待事件 示例处理器
 * 模拟：当用户扫条码获取产品自动加入购物车
 */
class MenuScancodeWaitmsgTest extends EventHandle implements EventHandleInterface
{
    private $code_info;
    private $carts;
    // 测试产品条码库
    private $products=[
        '0A2938',   
        '1X2928', 
    ];
    
    
    public function handle()
    {
        $this->code_info = $this->message['ScanCodeInfo'];
		
        if($this->code_info['ScanType'] != 'barcode'){
            return '只能扫商品条码哦！';
        }
        
        $barcode_datas = explode(',',$this->code_info['ScanResult']);
        if(in_array($barcode_datas[1],$this->products)){
            $this->carts[] = $barcode_datas[1];
            return '商品加入购物车成功！';
        }
    }
}
